package com.sven.cloudseataorder.service.impl;

import com.sven.cloudseataorder.fegin.StockFegin;
import com.sven.cloudseataorder.mapper.OrderMapper;
import com.sven.cloudseataorder.service.OrderService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class OrderServiceImpl implements OrderService {
    @Resource
    private OrderMapper orderMapper;
    @Resource
    private StockFegin stockFegin;

    // 开启分布式事务
    @GlobalTransactional
    @Override
    public void create() {
        //减库存
        stockFegin.decrement();

        //添加异常
        int i=1/0;

        //创建订单
        orderMapper.create();
    }
}
